home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr29 / memsize.zip / CONFIG.CPP < prev    next >
Text File  |  1995-01-04  |  11KB  |  275 lines

  1. /***************************************************************** CONFIG.CPP
  2.  *                                                                          *
  3.  *                        Clock Configuration Dialog                        *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #define INCL_WINSTDSPIN
  10. #include <os2.h>
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17.  
  18. #include "memsize.h"
  19. #include "config.h"
  20.  
  21.  
  22. /****************************************************************************
  23.  *                                                                          *
  24.  *                     Definitions & Declarations                           *
  25.  *                                                                          *
  26.  ****************************************************************************/
  27.  
  28.   // Function Prototypes
  29.  
  30. static METHODFUNCTION InitDlg ;
  31. static METHODFUNCTION Command ;
  32. static METHODFUNCTION OK ;
  33. static METHODFUNCTION Cancel ;
  34.  
  35.  
  36. /****************************************************************************
  37.  *                                                                          *
  38.  *      "Configure" Dialog Processor                                            *
  39.  *                                                                          *
  40.  ****************************************************************************/
  41.  
  42. extern MRESULT EXPENTRY ConfigureProcessor
  43. (
  44.   HWND hwnd,
  45.   USHORT msg,
  46.   MPARAM mp1,
  47.   MPARAM mp2
  48. )
  49. {
  50.  /***************************************************************************
  51.   *                             Declarations                                *
  52.   ***************************************************************************/
  53.  
  54.   static METHOD Methods [] =
  55.   {
  56.     { WM_INITDLG, InitDlg },
  57.     { WM_COMMAND, Command }
  58.   } ;
  59.  
  60.  /***************************************************************************
  61.   * Dispatch the message according to the method table and return the       *
  62.   *   result.  Any messages not defined above get handled by the system     *
  63.   *   default dialog processor.                                             *
  64.   ***************************************************************************/
  65.  
  66.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  67. }
  68.  
  69. /****************************************************************************
  70.  *                                                                          *
  71.  *      Initialize Dialog                                                   *
  72.  *                                                                          *
  73.  ****************************************************************************/
  74.  
  75. static MRESULT APIENTRY InitDlg
  76.   HWND hwnd, 
  77.   USHORT msg,
  78.   MPARAM mp1, 
  79.   MPARAM mp2
  80. )
  81. {
  82.  /***************************************************************************
  83.   * Get initial parameters.                                                 *
  84.   ***************************************************************************/
  85.  
  86.   PCONFIG_PARMS Parms = (PCONFIG_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  87.  
  88.   WinSetWindowPtr ( hwnd, QWL_USER, Parms ) ;
  89.  
  90.  /***************************************************************************
  91.   * Associate the help instance.                                            *
  92.   ***************************************************************************/
  93.  
  94.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  95.  
  96.   if ( Parms->hwndHelp )
  97.   {
  98.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  99.   }
  100.  
  101.  /***************************************************************************
  102.   * Load the list box.                                                      *
  103.   ***************************************************************************/
  104.  
  105.   for ( int i=0; i<Parms->ItemCount; i++ )
  106.   {
  107.     WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_INSERTITEM,
  108.       MPFROMSHORT(LIT_END), MPFROMP(Parms->ItemNames[i]) ) ;
  109.  
  110.     if ( Parms->ItemFlags[i] )
  111.     {
  112.       WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_SELECTITEM,
  113.         MPFROMSHORT(SHORT(i)), MPFROMSHORT(TRUE) ) ;
  114.     }
  115.   }
  116.  
  117.  /***************************************************************************
  118.   * Set the radio button and checkbox values.                               *
  119.   ***************************************************************************/
  120.  
  121.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_HIDECONTROLS,
  122.     BM_SETCHECK, MPFROMSHORT(Parms->HideControls), 0 ) ;
  123.  
  124.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_FLOAT,
  125.     BM_SETCHECK, MPFROMSHORT(Parms->Float), 0 ) ;
  126.  
  127.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ANIMATE,
  128.     BM_SETCHECK, MPFROMSHORT(Parms->Animate), 0 ) ;
  129.  
  130.  /***************************************************************************
  131.   * Set the limits and initial value of the spin-button control.            *
  132.   ***************************************************************************/
  133.  
  134.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  135.     SPBM_SETLIMITS, (MPARAM)300L, (MPARAM)10L ) ;
  136.  
  137.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  138.     SPBM_SETCURRENTVALUE, (MPARAM)(Parms->TimerInterval/100), NULL ) ;
  139.  
  140.  /***************************************************************************
  141.   * Return without error.                                                   *
  142.   ***************************************************************************/
  143.  
  144.   return ( MRFROMSHORT ( FALSE ) ) ;
  145. }
  146.  
  147. /****************************************************************************
  148.  *                                                                          *
  149.  *      Process commands received by the Configure Dialog                       *
  150.  *                                                                          *
  151.  ****************************************************************************/
  152.  
  153. static MRESULT APIENTRY Command
  154.   HWND hwnd, 
  155.   USHORT msg, 
  156.   MPARAM mp1, 
  157.   MPARAM mp2
  158. )
  159. {
  160.  /***************************************************************************
  161.   * Local Declarations                                                      *
  162.   ***************************************************************************/
  163.  
  164.   static METHOD Methods [] =
  165.   {
  166.     { DID_OK,     OK     },
  167.     { DID_CANCEL, Cancel },
  168.   } ;
  169.  
  170.  /***************************************************************************
  171.   * Dispatch the message without a default message processor.               *
  172.   ***************************************************************************/
  173.  
  174.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), PFNWP(NULL) ) ) ;
  175. }
  176.  
  177. /****************************************************************************
  178.  *                                                                          *
  179.  *      Process the Configure Dialog's OK button being pressed.             *
  180.  *                                                                          *
  181.  ****************************************************************************/
  182.  
  183. static MRESULT APIENTRY OK
  184.   HWND hwnd, 
  185.   USHORT msg, 
  186.   MPARAM mp1, 
  187.   MPARAM mp2
  188. )
  189. {
  190.  /***************************************************************************
  191.   * Find the instance data.                                                 *
  192.   ***************************************************************************/
  193.  
  194.   PCONFIG_PARMS Parms = PCONFIG_PARMS ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  195.  
  196.  /***************************************************************************
  197.   * Query the list box items for their selection.                           *
  198.   ***************************************************************************/
  199.  
  200.   for ( int i=0; i<Parms->ItemCount; i++ )
  201.   {
  202.     Parms->ItemFlags[i] = FALSE ;
  203.   }
  204.  
  205.   SHORT Selection = LIT_FIRST ;
  206.   do
  207.   {
  208.     Selection = BOOL ( SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  209.       IDD_CONFIG_ITEMS, LM_QUERYSELECTION,
  210.       MPFROMSHORT(SHORT(Selection)), 0 ) ) ) ;
  211.  
  212.     if ( Selection != LIT_NONE )
  213.     {
  214.       Parms->ItemFlags[Selection] = TRUE ;
  215.     }
  216.   }
  217.   while ( Selection != LIT_NONE ) ;
  218.  
  219.  /***************************************************************************
  220.   * Query the buttons for their new settings.                               *
  221.   ***************************************************************************/
  222.  
  223.   Parms->HideControls = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  224.     IDD_CONFIG_HIDECONTROLS, BM_QUERYCHECK, 0L, 0L ) ) ;
  225.  
  226.   Parms->Float = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  227.     IDD_CONFIG_FLOAT, BM_QUERYCHECK, 0L, 0L ) ) ;
  228.  
  229.   Parms->Animate = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  230.     IDD_CONFIG_ANIMATE, BM_QUERYCHECK, 0L, 0L ) ) ;
  231.  
  232.  /***************************************************************************
  233.   * Query the spinbuttons for their new settings.                           *
  234.   ***************************************************************************/
  235.  
  236.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER, SPBM_QUERYVALUE,
  237.     &Parms->TimerInterval, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  238.  
  239.   Parms->TimerInterval *= 100 ;
  240.  
  241.  /***************************************************************************
  242.   * Dismiss the dialog with a TRUE status.                                  *
  243.   ***************************************************************************/
  244.  
  245.   WinDismissDlg ( hwnd, TRUE ) ;
  246.  
  247.   return ( 0 ) ;
  248. }
  249.  
  250. /****************************************************************************
  251.  *                                                                          *
  252.  *      Process the Configure Dialog's being cancelled.                     *
  253.  *                                                                          *
  254.  ****************************************************************************/
  255.  
  256. static MRESULT APIENTRY Cancel
  257.   HWND hwnd, 
  258.   USHORT msg, 
  259.   MPARAM mp1, 
  260.   MPARAM mp2
  261. )
  262. {
  263.  /***************************************************************************
  264.   * Dismiss the dialog with a TRUE status.                                  *
  265.   ***************************************************************************/
  266.  
  267.   WinDismissDlg ( hwnd, FALSE ) ;
  268.  
  269.   return ( 0 ) ;
  270. }
  271.